package com.sl.biz.modular.thread.controller;

import cn.hutool.core.thread.RejectPolicy;
import com.sl.biz.modular.thread.controller.response.ProcessThreadConfigVO;
import com.sl.biz.modular.thread.dao.domain.entity.ProcessThreadConfigDO;
import com.sl.biz.modular.thread.service.ProcessThreadConfigBizService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.compress.utils.Lists;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/process/thread/config")
@RequiredArgsConstructor
public class ProcessThreadConfigController {


    private final ProcessThreadConfigBizService threadConfigBizService;


    @PostMapping("/list")
    public List<ProcessThreadConfigVO> list(@RequestBody ProcessThreadConfigDO processThreadConfig) {
        return threadConfigBizService.list(processThreadConfig);
    }

    @PostMapping("/time_unit_list")
    public List<Map<String, Object>> timeUnitList() {
        List<Map<String, Object>> resList = Lists.newArrayList();
        for (TimeUnit value : TimeUnit.values()) {
            Map<String, Object> h = new HashMap<>();
            h.put("code", value.name());
            h.put("name", value.name());
            resList.add(h);
        }
        return resList;
    }


    @PostMapping("/reject_policy_list")
    public List<Map<String, Object>> rejectPolicyList() {
        List<Map<String, Object>> resList = Lists.newArrayList();
        for (RejectPolicy value : RejectPolicy.values()) {
            Map<String, Object> h = new HashMap<>();
            h.put("code", value.name());
            h.put("name", value.name());
            resList.add(h);
        }
        return resList;
    }

    @PostMapping("/save")
    public Boolean save(@RequestBody ProcessThreadConfigDO threadConfigDO) {
        return threadConfigBizService.save(threadConfigDO);
    }

    @PostMapping("/get_by_id")
    public ProcessThreadConfigVO getById(@RequestBody ProcessThreadConfigDO threadConfigDO) {
        return threadConfigBizService.getById(threadConfigDO);
    }

    @PostMapping("/thread_stack_trace")
    public Map<String, String> threadStackTrace(@RequestBody @Validated ProcessThreadConfigDO assertUserUse) {
        return threadConfigBizService.threadStackTrace(assertUserUse);
    }

    @PostMapping("/set_status_flag")
    public Boolean setStatusFlag(@RequestBody @Validated ProcessThreadConfigDO assertUserUse) {
        return threadConfigBizService.setStatusFlag(assertUserUse);
    }

}
